package com.dayuanit.dy16.atm.handler;

import com.baidu.aip.speech.AipSpeech;
import com.baidu.aip.speech.TtsResponse;
import org.springframework.stereotype.Component;

@Component
public class VoiceHandler {
    public static final String APP_ID = "19541681";
    public static final String API_KEY = "9nLzAyHwYp0mMPskqSpT8oQt";
    public static final String SECRET_KEY = "eZKg2RFwBKtNit6HPGKgtQREKzl3wNNR";

    public byte[] makeVoice(String msg) {
        // 初始化一个AipSpeech
        AipSpeech client = new AipSpeech(APP_ID, API_KEY, SECRET_KEY);

        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);

        // 调用接口
        TtsResponse res = client.synthesis(msg, "zh", 1, null);
        byte[] data = res.getData();
        System.out.println("voice data size=" +  data.length);
        return data;
    }

}
